package server;

import java.util.ArrayList;

import shared.ChatMessage;

public class ConnectionList {

	ArrayList<Connection> connections;
	
	public ConnectionList() {
		connections=new ArrayList<Connection>();
	}
	
	public void add(Connection con) {
		connections.add(con);
	}
	
	public void sendToAll(ChatMessage chatMessage) {
		for (int i=0; i<connections.size();i++) {
			Connection c=connections.get(i);
			if (!c.isClosed()) {
				c.sendMessage(chatMessage);
			} else {
				connections.remove(i);
				i--;
			}
		}
	}
}
